package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.bumptech.glide.RequestManager;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.EmploymentEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.StringUtil;

import java.util.List;

/**
*@author liwei
*@date 2020/11/10
*description:
*/
public class PackersEmploymentAdapter extends BaseRecycleAdapter<EmploymentEntity> {

    private int isSearch = 0;
    private boolean isHide = false;

    public PackersEmploymentAdapter(Context context, List<EmploymentEntity> data, int isSearch) {
        super(context, R.layout.item_packers_employment, data);
        this.isSearch = isSearch;
    }

    public PackersEmploymentAdapter(Context context, List<EmploymentEntity> data, boolean isHide) {
        super(context, R.layout.item_packers_employment, data);
        this.isHide = isHide;
    }

    @Override
    public void convert(ItemViewHolder holder, EmploymentEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView tvTime = holder.itemView.findViewById(R.id.tv_end_time);
        TextView packersStart = holder.itemView.findViewById(R.id.packers_start);
        TextView pkEmploymentType = holder.itemView.findViewById(R.id.pk_employment_type);
        TextView tvPrice = holder.itemView.findViewById(R.id.tv_price);
        //工期
        TextView tvGq = holder.itemView.findViewById(R.id.tv_gq);

        switch (entity.getSalaryType()) {
            case 1:
                tvPrice.setText("面议");
                break;
            case 2:
                tvPrice.setText("电议");
                break;
            case 3:
                String salary = entity.getSalary();
                if (entity.getSalary().startsWith("-") || entity.getSalary().endsWith("-")){
                    salary = entity.getSalary().replace("-","");
                }
                tvPrice.setText(String.format("%s%s%s",salary , "元/" , entity.getSalaryUnitName()));
                break;
            default:
                break;
        }
        tvGq.setText(String.format("%s%s",StringUtil.formatDouble(Double.parseDouble(entity.getDuration())), entity.getDurationUnitName()));
        if (!TextUtils.isEmpty(entity.getIndustryName())) {
            if (!TextUtils.isEmpty(entity.getCategoryName())) {
                pkEmploymentType.setVisibility(View.VISIBLE);
                pkEmploymentType.setText(String.format("%s/%s",entity.getIndustryName() , entity.getCategoryName()));
            } else {
                pkEmploymentType.setVisibility(View.VISIBLE);
                pkEmploymentType.setText(entity.getIndustryName());
            }
        } else {
            if (!TextUtils.isEmpty(entity.getCategoryName())) {
                pkEmploymentType.setText(entity.getCategoryName());
                pkEmploymentType.setVisibility(View.VISIBLE);
            } else {
                pkEmploymentType.setText("");
                pkEmploymentType.setVisibility(View.GONE);
            }
        }
        tvTime.setText(String.format("%s%s",DateUtils.timestampToDate(entity.getCreateTime()) , "发布"));
        TextView tvWorkerNum = holder.itemView.findViewById(R.id.tv_worker_num);
        tvWorkerNum.setText(String.format("%s%s",entity.getEmploymentNumber() , "人"));
        if (TextUtils.isEmpty(entity.getEmploymentStatusName()) || "招工中".equals(entity.getEmploymentStatusName())) {
            packersStart.setText("招工中");
            packersStart.setBackground(ContextCompat.getDrawable(context,R.drawable.bg_corner2_5792fd));
            packersStart.setTextColor(ContextCompat.getColor(context,R.color.new_blue));
        } else {
            packersStart.setText("急招");
            packersStart.setBackground(ContextCompat.getDrawable(context,R.drawable.bg_goods_info_strock_red_line4));
            packersStart.setTextColor(ContextCompat.getColor(context,R.color.new_org2));
        }
        TextView tvAddress = holder.itemView.findViewById(R.id.tv_address);
        if (isSearch == 0) {
            tvAddress.setText(entity.getAddressAll());
        } else if (isSearch == 1) {
            tvAddress.setText(entity.getAddress());
        } else {
            tvAddress.setText(entity.getAddressAll());
        }
        ImageView linView = holder.itemView.findViewById(R.id.iv_tag);
        if (isHide){
            linView.setVisibility(View.GONE);
        }else {
            linView.setVisibility(View.VISIBLE);
        }
    }
}
